package com.example.timernote

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    lateinit var list: MutableList<BloodPressureInfo>
    lateinit var adapter:RvAdapter

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        list = mutableListOf()
        adapter= RvAdapter(list,this)

        var mRv = findViewById<RecyclerView>(R.id.mRvMainContent)
        mRv.layoutManager = LinearLayoutManager(this)
        mRv.adapter = adapter




        mFbtnAdd.setOnClickListener(object : View.OnClickListener{
            override fun onClick(v: View?) {
                startActivity(Intent(this@MainActivity,AddNoteActivity::class.java))
            }
        })


    }

    override fun onResume() {
        super.onResume()
        initList(list)
        adapter.notifyDataSetChanged()
    }

    private fun initList(list: MutableList<BloodPressureInfo>) {
        list.clear()
        list.addAll(BloodPressureInfoService.selectAll())
    }
}
